From 24766152fcaeef4b48420e4916806c3e31cf8442 Mon Sep 17 00:00:00 2001 From: robertl Date: Fri, 6 Feb 2004 08:17:24 +0000 Subject: [PATCH] sroute, tiger, mapsource: ascii-ify output --- gpsbabel/mapsource.c | 9 ++++++--- gpsbabel/saroute.c | 7 ++++--- gpsbabel/tiger.c | 6 ++++-- gpsbabel/util.c | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/gpsbabel/mapsource.c b/gpsbabel/mapsource.c index 0dcbcf102..dbd9b3af3 100644 --- a/gpsbabel/mapsource.c +++ b/gpsbabel/mapsource.c @@ -585,6 +585,7 @@ mps_waypoint_w(FILE *mps_file, int mps_ver, const waypoint *wpt, const int isRou int icon; char *src; char *ident; + char *ascii_description; char zbuf[25]; char ffbuf[25]; int display = 1; @@ -613,7 +614,8 @@ mps_waypoint_w(FILE *mps_file, int mps_ver, const waypoint *wpt, const int isRou icon = mps_converted_icon_number(icon, mps_ver, MAPSOURCE); /* two NULL (0x0) bytes at end of each string */ - reclen = strlen(ident) + ((wpt->description) ? strlen(wpt->description) : 0) + 2; + ascii_description = wpt->description ? str_utf8_to_ascii(wpt->description) : xstrdup(""); + reclen = strlen(ident) + strlen(ascii_description) + 2; if ((mps_ver == 4) || (mps_ver == 5)) { /* v4.06 & V5.0*/ reclen += 85; /* "W" (1) + strlen(name) + NULL (1) + class(4) + country(sz) + @@ -670,9 +672,10 @@ mps_waypoint_w(FILE *mps_file, int mps_ver, const waypoint *wpt, const int isRou fwrite(hdr, 1 , 1, mps_file); fwrite(&mps_altitude, 8 , 1, mps_file); } - - if (wpt->description) fputs(wpt->description, mps_file); + if (wpt->description) fputs(ascii_description, mps_file); fwrite(zbuf, 1, 1, mps_file); /* NULL termination */ + xfree(ascii_description); + ascii_description = NULL; if (mps_proximity == unknown_alt) { fwrite(zbuf, 9, 1, mps_file); diff --git a/gpsbabel/saroute.c b/gpsbabel/saroute.c index 5a0ee80c4..a4725ef54 100644 --- a/gpsbabel/saroute.c +++ b/gpsbabel/saroute.c @@ -82,8 +82,8 @@ my_read(void) unsigned short version; unsigned long count; unsigned long recsize; - unsigned char *record; unsigned short stringlen; + unsigned char *record; static int serial = 0; struct ll { long lat; @@ -116,7 +116,7 @@ my_read(void) stringlen = le_read16((unsigned short *)(record + 0x1a)); Skip(infile, stringlen - 4); - free(record); + xfree(record); /* * end of filename record @@ -151,6 +151,7 @@ my_read(void) wpt_tmp->shortname = xmalloc(7); sprintf( wpt_tmp->shortname, "\\%5.5x", serial++ ); route_add_wpt(track_head, wpt_tmp); + xfree(record); } else { Skip(infile, recsize); /* @@ -219,7 +220,7 @@ my_read(void) latlon++; coordcount--; } - free(record); + xfree(record); } /* * end of routing diff --git a/gpsbabel/tiger.c b/gpsbabel/tiger.c index f0e202bf5..865b5d7a5 100644 --- a/gpsbabel/tiger.c +++ b/gpsbabel/tiger.c @@ -170,10 +170,12 @@ tiger_disp(const waypoint *wpt) fprintf(file_out, "%f,%f:%s", lon, lat, pin); if (!nolabels) { char *desc = csv_stringclean(wpt->description, ":"); + char *adesc = str_utf8_to_ascii(desc); if (global_opts.synthesize_shortnames) - desc = mkshort(mkshort_whandle, desc); - fprintf(file_out, ":%s", desc); + adesc = mkshort(mkshort_whandle, adesc); + fprintf(file_out, ":%s", adesc); xfree(desc); + xfree(adesc); } fprintf(file_out, "\n"); } diff --git a/gpsbabel/util.c b/gpsbabel/util.c index 309f80fad..f4628e316 100644 --- a/gpsbabel/util.c +++ b/gpsbabel/util.c @@ -193,7 +193,7 @@ xrealloc(void *p, size_t s) if (!o) { fatal("gpsbabel: Unable to realloc %d bytes of memory.\n", s); - } + } return o; } -- 2.30.2